﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;

namespace Managistics.Model.Mappings
{
    public class PurchaseOrderMap : ClassMap<PurchaseOrder>
    {

        public PurchaseOrderMap()
        {
            Schema(Constants._tblSchema);
            Table(Constants._tblOrderSupplier);
            LazyLoad();

            Id(x => x.Orderid).GeneratedBy.Assigned().Column("ORDERID_NN");
            References(x => x.Employee).Column("EMPLOYEEID");
            References(x => x.Supplier).Column("SUPPLIERID").Fetch.Join();

            Map(x => x.Orderdate).Column("ORDERDATE_NN").Not.Nullable();
            Map(x => x.Requestdate).Column("REQUESTDATE_NN");
            Map(x => x.ShippingDate).Column("SHIPPING_DATE_NN").Not.Nullable();
            Map(x => x.ShipAddress).Column("SHIP_ADDRESS_NN").Length(250);
            Map(x => x.Status).Column("STATUS_NN").Not.Nullable();
            Map(x => x.Note).Column("NOTE_NN").Length(200);
            Map(x => x.CompleteDate).Column("COMPLETE_DATE_PO");
            Map(x => x.TypeVat).Column("TYPE_VAT").Precision(5);
            Map(x => x.PayCondition).Column("PAY_CONDITION").Length(50);
            Map(x => x.NumInput).Column("num_input").Not.Nullable().Precision(5);
            Map(x => x.NumReturn).Column("num_return").Not.Nullable().Precision(5);
            Map(x => x.Discount).Column("Discount").Not.Nullable().Precision(53);

            HasMany(x => x.PurchaseOrderDetail).KeyColumn("ORDERID_NN").Inverse().Not.LazyLoad();
        }
    }
}
